package mongo.db.clients.firsts;

import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.List;

import com.mongodb.BasicDBObject;
import com.mongodb.DB;
import com.mongodb.DBCollection;
import com.mongodb.MongoClient;
import com.mongodb.ServerAddress;

public class DropAndCreateIndex {

	public static void main(String[] args) {

		List<ServerAddress> seeds = new ArrayList<ServerAddress>();

		try {
			seeds.add(new ServerAddress("202.191.136.234", 27017));
//			seeds.add(new ServerAddress("172.31.1.5", 27017));
		} catch (UnknownHostException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		MongoClient client = new MongoClient(seeds);

		DB db = client.getDB("netflowdb1");
		db.dropDatabase();

		DBCollection collection = db.getCollection("netflow_column1");
//		collection.dropIndexes();
		
		collection.ensureIndex(new BasicDBObject("routerip", 1));
		collection.ensureIndex(new BasicDBObject("routerip", 1).append("intputint", 1));
		collection.ensureIndex(new BasicDBObject("routerip", 1).append("outputint", 1));
		collection.ensureIndex(new BasicDBObject("timestamp", 1), new BasicDBObject("expireAfterSeconds", 7200));
//		collection.dropIndexes();
		
		if ( collection.getIndexInfo().size() > 1 ) {
			System.out.println("index present");
		} else {
			System.out.println("no index");
		}
	}

}
